package main

import (
	"fmt"
	"gitee.com/chenwl888/gotools/utils/log"
	"github.com/ian-kent/go-log/appenders"
	log2 "github.com/ian-kent/go-log/log"
	"time"
)

type Object struct {
	Type      uint32          `protobuf:"varint,1,opt,name=Type,proto3" json:"Type,omitempty"`
	Id        uint64          `protobuf:"varint,2,opt,name=Id,proto3" json:"Id,omitempty"`
	Param1    int64           `protobuf:"varint,11,opt,name=Param1,proto3" json:"Param1,omitempty"`
	Param2    int64           `protobuf:"varint,12,opt,name=Param2,proto3" json:"Param2,omitempty"`
	Param3    int64           `protobuf:"varint,13,opt,name=Param3,proto3" json:"Param3,omitempty"`
	Roles     map[uint32]bool `protobuf:"bytes,30,rep,name=Roles,proto3" json:"Roles,omitempty" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"`
	StrParam1 string          `protobuf:"bytes,36,opt,name=StrParam1,proto3" json:"StrParam1,omitempty"`
}

func main() {
	processName := "myprocess"
	logger, err := log.NewLogger(processName, 10)
	if err != nil {
		fmt.Println("Failed to create logger:", err)
		return
	}
	defer logger.Close()

	logger.Info("This is a log message. %v", 111)
	logger.Info(map[int]int{1: 100, 2: 200})
	logger.Notice("This is a log message. %v", 111)
	logger.Debug("This is a log message. %v", 111)
	logger.Error("This is a log message. %v", 111)
	logger.Error("This is a obj %v", Object{
		Type: 111,
		Id:   234,
	})

	format := "交任务条件不满足 TaskId:=%v"
	v := []interface{}{111}
	s := fmt.Sprintf("[%v-%v,%d-%d,%d]%s", 21213, "adsasad",
		2124123, 324352, 345432, format)

	// 这是项目中错误的
	var sss []interface{}
	sss = append(sss, s)
	sss = append(sss, v...)
	logger.Info2(sss...)
	logger.Info2(map[int]int{1: 100, 2: 200})
	time.Sleep(4 * time.Second)
	logger.Error("This is a log message11111111111. %v", 111)

	logger2 := log2.Logger()
	logger2.Debug("Yey!")
	logger2.SetAppender(appenders.Console())
	// 追加到（或创建）文件
	logger2.SetAppender(appenders.RollingFile("filename.log", true))
	// 截断（或创建）文件
	//logger2.SetAppender(appenders.RollingFile("filename.log", false))
	// 直接传递日志消息和参数
	logger2.Debug("Example log message: %s", "example arg")
	logger2.Error("Example log message: %s", "example arg")

	// 传递返回日志消息和参数的函数
	logger2.Debug(func() []interface{} { return []interface{}{"Example log message: %s", "example arg"} })
	logger2.Debug(func(i ...interface{}) []interface{} { return []interface{}{"Example log message: %s", "example arg"} })
}
